#coding=utf-8 
import sys  
reload(sys)  
sys.setdefaultencoding('utf-8') 
import os
import shutil
from selenium import webdriver
from ec.util import commonUtil
from ec.test import landingCase
from ec.test.landingTest import LangdingTest
from ec.test.orderTest import OrderTest
from plugin import HTMLTestRunner
import logging
import unittest

def main():
	logging.basicConfig(level=logging.ERROR,
                format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
                datefmt='%a, %d %b %Y %H:%M:%S',
                filemode='w')

	browser = commonUtil.initIeDriver()
	browser.maximize_window()

	#清除之前的错误报告
	if os.path.exists("report"+os.sep+"report.html"):
		os.remove("report"+os.sep+"report.html")
	if os.path.exists("report"+os.sep+"errorImage"):
		shutil.rmtree("report"+os.sep+"errorImage")
	suite = unittest.TestSuite()
	suite.addTest(LangdingTest("testLoginInFail",browser))
	suite.addTest(LangdingTest("testLoginInSuccess",browser))
	suite.addTest(OrderTest("testPayOrder",browser))
	# unittest.TextTestRunner(verbosity=2).run(suite)

	filename="report"+os.sep+"report.html"  #定义个报告存放路径，支持相对路径。
	fp=file(filename,'wb')
	#使用HTMLTestRunner配置参数，输出报告路径、报告标题、描述
	runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='自动测试报告',description='Report_description')  
	runner.run(suite) #自动进行测试
	browser.get("file:///"+os.getcwd()+"/report/report.html")


if __name__=="__main__":
	print "start auto ui test !'\n"
	main()
	print "auto ui test end!'\n"
